﻿
@{
    Layout = null;
}
@using Model
@model salary_standard

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-trasitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../../css/table.css" type="text/css" />
    <script type="text/javascript" src="../../javascript/comm/comm.js"></script>
    <script type="text/javascript" src="../../javascript/jquery-1.7.2.js"></script>
    <script src="~/js/jquery-1.11.1.js"></script>
    <script src="~/js/vue.js"></script>
    <title>薪酬标准登记</title>
    <script>
        $(function () {
            //全选和全不选
            $('#quan').bind('click', function () {
                if (this.checked) {    //全选
                    $("input[id^='sid']").each(function () {
                        $(this).prop('checked', true);
                    })
                } else {    //全不选
                    $("input[id^='sid']").each(function () {
                        $(this).prop('checked', false);
                    })
                }
            });
            //所有的子项选中或者不全选中后，全选按钮也选中或者不选中

            var allLength = $("input[id^=sid]").length; //所有的checkbox的长度
            $("input[id^=sid]").each(function () {
                $(this).bind('click', function () {
                    var selectedLength = $("input[id^=sid]:checked").length;//所有的选中的checkbox的长度
                    if (selectedLength == allLength) {
                        $('#quan').prop("checked", true);//全选按钮
                    } else {
                        $('#quan').prop("checked", false);
                    }

                })

            })
        })

    </script>
</head>
<body>
    <div id="app">
        <form id="form1">
            <table width="100%">
                <tr>
                    <td>
                        <font color="black">
                            您正在做的业务是：人力资源--薪酬标准管理--薪酬标准登记
                        </font>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <input type="button" value="提 交" v-on:click="Add()" class="BUTTON_STYLE1">
                        <input type="reset" value="返 回" class="BUTTON_STYLE1">
                    </td>
                </tr>
            </table>
            <table id="stable" width="100%" border="1" cellpadding=0 cellspacing=1
                   bordercolorlight=#848284 bordercolordark=#eeeeee
                   class="TABLE_STYLE1">
                <tr>
                    <td width="74" class="TD_STYLE1">
                        薪酬标准编号
                    </td>
                    <td width="168" class="TD_STYLE2">
                        <input type="text" id="standard_id" name="standard_id" asp-for="standard_id" readonly="readonly" class="INPUT_STYLE2">
                    </td>
                    <td width="83" class="TD_STYLE1">
                        薪酬标准名称
                    </td>
                    <td width="171" class="TD_STYLE2">
                        <input type="text" name="standard_name" asp-for="standard_name" id="standardName" class="INPUT_STYLE2">
                        <span id="xcname" style="color:red;font-weight:bold;">请输入薪酬标准名称！</span>
                    </td>
                    <td width="170" class="TD_STYLE1">
                        薪酬总额
                    </td>
                    <td width="138" class="TD_STYLE2">
                        <input type="text" name="salary_sum" id="sumSalary" asp-for="salary_sum" value="0.0" readonly class="INPUT_STYLE2" />
                    </td>
                    <td width="103" class="TD_STYLE1">
                        &nbsp;
                    </td>
                    <td width="95" height="26" class="TD_STYLE2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="TD_STYLE1">
                        制定人
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" id="designer" name="designer" asp-for="designer" class="INPUT_STYLE2">
                        <span id="zdr" style="color:red;font-weight:bold;">请输入制定人！</span>
                    </td>
                    <td class="TD_STYLE1">
                        登记人
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" id="register" name="register" asp-for="register" class="INPUT_STYLE2">
                        <span id="djr" style="color:red;font-weight:bold;">请输入登记人！</span>
                    </td>
                    <td class="TD_STYLE1">
                        登记时间
                    </td>
                    <td class="TD_STYLE2">
                        <input type="text" id="Tdate" name="regist_time" asp-for="regist_time" readonly="readonly" class="INPUT_STYLE2">
                    </td>
                    <td class="TD_STYLE1">
                        &nbsp;
                    </td>
                    <td class="TD_STYLE2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="TD_STYLE1">
                        备注
                    </td>
                    <td colspan="7" class="TD_STYLE2">
                        <textarea name="remark" rows="4" asp-for="remark" class="TEXTAREA_STYLE1"></textarea>
                        <span asp-validation-for="remark"></span>
                    </td>
                </tr>
                <tr class="TD_STYLE1">
                    <td align="center">
                        序号
                    </td>
                    <td colspan="3">
                        薪酬项目名称
                    </td>
                    <td>
                        金额
                    </td>
                    <td colspan="3">
                        &nbsp;
                    </td>
                </tr>

                <tbody id="tbody">
                    <tr class="TD_STYLE2" v-for="(item,index) in dt">
                        <td align="center">
                            {{index+1}}
                            <input type="hidden" name="item_id" id="item_id" v-bind:value="index+1">
                        </td>
                        <td colspan="3">
                            {{item}}
                            <input type="hidden" id="item_name" name="iname" v-bind:value="item">
                        </td>
                        <td>
                            <input type="text" id="salary" value="0.00" name="salary"
                                   onkeyup="countMoney('6','salary')" class="INPUT_STYLE2">
                        </td>
                        <td colspan="3">
                            &nbsp;
                        </td>
                    </tr>
                </tbody>
            </table>
            <span class="sss">
                <input type="checkbox" name="quan" id="quan" />全选
                <input id="Button1" type="button" value="请选择薪酬组成" v-on:click="choice()" />
            </span>
            <br />
            <span class="TD_STYLE2 sss">
                <input type="checkbox" name="item_name" id="sid" value="出差补助" />出差补助
                <input type="checkbox" name="item_name" id="sid" value="交通补贴" />交通补贴
                <input type="checkbox" name="item_name" id="sid" value="住房补贴" />住房补贴
                <input type="checkbox" name="item_name" id="sid" value="基本工资" />基本工资
                <input type="checkbox" name="item_name" id="sid" value="年终奖" />年终奖
                <input type="checkbox" name="item_name" id="sid" value="误餐补助" />误餐补助
            </span>
            <p>
                &nbsp;
            </p>
        </form>
    </div>
    <script type="text/javascript">
        function countMoney(obj, o) {
            obj = vm.leg;
            if (isNaN(document.getElementById(o).value) || document.getElementById(o).value < 0) {
                alert("金额填写错误!");
                document.getElementById(o).value = "0.00";
                return;
            }
            var sum = 0;
            for (var i = 0; i < obj; i++) {
                var salary = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(3) input").val();
                if (salary == null || salary == "" || salary == NaN || salary == "0.00") {
                    salary = 0;
                }
                sum = Number(sum) + Number(salary);
            }
            document.getElementById("sumSalary").value = sum;

        }
        function time() {
            var tdate = document.getElementById("Tdate");
            var d = new Date();
            var y = d.getFullYear();
            var moth = d.getMonth() + 1;
            var date = d.getDate();
            var h = d.getHours();
            var m = d.getMinutes();
            var s = d.getSeconds();
            var hh = 20 - 1 - h;
            var mm = 60 - 1 - m;
            var ss = 60 - s;
            if (hh > 0) {
                mm = mm + 60 * hh;
            }
            if (moth < 10) {
                moth = "0" + moth;
            }
            if (date < 10) {
                date = "0" + date;
            }
            if (h < 10) {
                h = "0" + h;
            }
            if (m < 10) {
                m = "0" + m;
            }
            if (s < 10) {
                s = "0" + s;
            }
            if (mm < 10) {
                mm = "0" + mm;
            }
            if (ss < 10) {
                ss = "0" + ss;
            }

            tdate.value = y + "-" + moth + "-" + date + " " + h + ":" + m + ":" + s;

        }
        window.onload = time;
        var out = window.setInterval(time, 1000);

        var vm = new Vue({
            el: "#app",
            data: {
                dt: [],
                leg: 0,
            },
            methods: {
                load: function () {
                    var t = this;
                    $("#zdr").hide();
                    $("#xcname").hide();
                    $("#djr").hide();
                },
                Add: function () {
                    var t = this;
                    var a = $("#standardName").val();
                    var b = $("#designer").val();
                    var c = $("#register").val();
                    if (a == null || a == "") {
                        $("#xcname").show();
                        return false;
                    } else if (b == null || b == "") {
                        $("#zdr").show();
                        return false;
                    } else if (c == null || c == "") {
                        $("#djr").show();
                        return false;
                    } else {
                        $.ajax({
                            url: "/xinchoubiaozhun/salarystandard_register",
                            type: "post",
                            data: $("#form1").serialize(),
                            success: function (msg) {
                                if (msg > 0) {
                                    t.XcAdd();
                                } else {
                                    alert('登记失败！');
                                }
                            }
                        })
                    }
                },
                choice: function () {
                    var t = this;
                    obj = document.getElementsByName("item_name");
                    check_val = [];
                    for (k in obj) {
                        if (obj[k].checked)
                            check_val.push(obj[k].value);
                    }
                    for (var i = 0; i < check_val.length; i++) {
                        var tt = check_val[i];
                        t.leg = i + 1;
                        t.dt.splice(i, 0, tt);
                        $(".sss").hide();
                    }
                },
                //获取薪酬标准编号
                standarId: function () {
                    //var num = Math.random();
                    //num = num * 100;
                    //num = Math.floor(num);
                    var randoms = [];
                    while (true) {
                        var isExists = false;
                        // 获取一个10–100范围的数
                        var random = parseInt(10 + (90 - 10) * (Math.random()))
                        // 判断bai当前随机数是否已经存du在
                        for (var i = 0; i < randoms.length; i++) {
                            if (random === randoms[i]) {
                                isExists = true;
                                break;
                            }
                        }
                        // 如果zhi不存在，则添加进去
                        if (!isExists)
                            randoms.push(random);
                        // 如果有10位随机数了，就跳出
                        if (randoms.length === 2)
                            break;
                    }
                    //把数组中的','用空代替
                    randoms = randoms.join('');
                    var data = new Date();
                    var year = data.getFullYear();
                    var month = data.getMonth() + 1;
                    var day = data.getDate();
                    var time = data.getHours();
                    var breanch = data.getMinutes();
                    var second = data.getSeconds();
                    $("#standard_id").val("XC"+year + month + day + time + breanch + second + randoms);
                },
                XcAdd: function () {
                    for (var i = 0; i < vm.leg; i++) {
                        var xh = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(1) input").val();
                        var name = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(2) input").val();
                        var salary = $("#tbody tr:nth-child(" + (i + 1) + ") td:nth-child(3) input").val();
                        $.ajax({
                            url: "/xinchoubiaozhun/xinchoufj",
                            type: "post",
                            data: { "item_name": name, "standard_id": $("#standard_id").val(), "item_id": xh, "standard_name": $("#standardName").val(), "salary": salary },
                            success: function (msg) {
                                if (msg > 0) {
                                    location.href = "/xinchoubiaozhun/salarystandard_register_success";
                                } else {
                                    alert('添加失败！');
                                }
                            }
                        })
                    }
                }
            },
            mounted: function () {
                this.load();
                this.standarId();
            }
        });
    </script>
</body>
</html>


